<template>
  <div :bordered="false">
    <f-table ref="table" rowKey="supplierRateId" :columns="columns" :multiple="false" :operator="operator" :autoLoad="false" :params="queryParam" :api="api.supplierRate">
        <span slot="action" slot-scope="text, record">
          <template>
              <a @click="editDrugsConfig(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.del(record)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <a-modal title="供货方费率配置" v-model="configModal" width="900px" height="500px" @cancel="handleCancel" @ok="handleSubmit">
      <f-form ref="drugsConfigForm" v-if="configModal" :action="api.supplierRate" :form-key="this.formItem.supplierRateId">
        <f-form-item label="垫付款税金费率" name="supplierTaxRate" type="number" data-type="number" :precision="4" :required="true" :value="formItem.supplierTaxRate"/>
        <f-form-item label="结算费率" name="supplierSettleRate" type="number" data-type="number" :precision="4" :required="true" :value="formItem.supplierSettleRate"/>
        <f-form-item label="返款公式" name="refundFormulaId" :required="true" type="select" :value="formItem.refundFormulaId" :data="api.formula.list" valueKey="formulaId" label-key="formulaContent" :params="params1"/>
        <f-form-item label="高开税金公式" name="highTaxRateFormulaId" :required="true" type="select" :value="formItem.highTaxRateFormulaId" :data="api.formula.list" valueKey="formulaId" label-key="formulaContent" :params="params2"/>
        <f-form-item label="生效日期" type="date" name="beginDate" :required="true" :value="formItem.beginDate"/>
        <f-form-item label="失效日期" type="date" name="endDate" :value="formItem.endDate"/>
      </f-form>
    </a-modal>
  </div>
</template>

<script>
  import api from './js/api'

  export default {
    name: 'SupplierRateDrugs',
    components: {},
    data() {
      let me = this
      //操作按钮
      let operator = []
      operator.push({
        name: '添加',
        icon: 'plus',
        that: this,
        handler: (table) => {
          this.configModal = true
          this.isEdit = false
          this.$refs['drugsConfigForm'].resetFields()
        }
      })
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {},
        isEdit: false,
        configModal: false,
        params1: {
          formulaType: 1
        },
        params2: {
          formulaType: 4
        },
        formItem: {
          supplierRateId: '',
          drugsId: '',
          supplierTaxRate: '',
          supplierSettleRate: '',
          refundFormulaId: '',
          highTaxRateFormulaId: '',
          beginDate: '',
          endDate: '',
          configState: ''
        },
        // 表头
        columns: [
          {
            title: '操作',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          },
          {
            title: '垫付款费率',
            align: 'center',
            dataIndex: 'supplierTaxRate'
          },
          {
            title: '结算费率',
            align: 'center',
            dataIndex: 'supplierSettleRate'
          },
          {
            title: '返款公式',
            align: 'center',
            dataIndex: 'r_formulaContent'
          },
          {
            title: '高开税金公式',
            align: 'center',
            dataIndex: 'h_formulaContent'
          },
          {
            title: '生效日期',
            align: 'center',
            dataIndex: 'beginDate'
          },
          {
            title: '失效日期',
            align: 'center',
            dataIndex: 'endDate'
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    methods: {
      setData(data) {
        if (data && data.drugsId) {
          this.queryParam.drugsId = data.drugsId
          this.$refs['table'].refresh(false)
        }
      },
      editDrugsConfig(bank) {
        this.formItem = bank
        this.configModal = true
        this.isEdit = true
      },
      handleSubmit() {
        this.$refs['drugsConfigForm'].submit({ drugsId: this.queryParam.drugsId }, this.handleCancel)
      },
      handleCancel() {
        this.configModal = false
        this.formItem = {}
      }
    }
  }
</script>